// Page2.cpp : implementation file
//

#include "stdafx.h"
#include "SpyXX.h"
#include "Page2.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPage2 dialog

HWND g_hPage2=NULL;
CPage2::CPage2(CWnd* pParent /*=NULL*/)
	: CDialog(CPage2::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPage2)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CPage2::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPage2)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPage2, CDialog)
	//{{AFX_MSG_MAP(CPage2)
	ON_CLBN_CHKCHANGE(IDC_LISTCLASS, &CPage2::OnLbnCheckchangeListClassStyle)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPage2 message handlers

BOOL CPage2::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	g_hPage2=m_hWnd;

	m_ClassStyleList.SubclassDlgItem(IDC_LISTCLASS, this);

	m_ClassStyleList.AddString("CS_BYTEALIGNCLIENT");
	m_ClassStyleList.AddString("CS_BYTEALIGNWINDOW");
	m_ClassStyleList.AddString("CS_CLASSDC");
	m_ClassStyleList.AddString("CS_DBLCLKS");
	m_ClassStyleList.AddString("CS_GLOBALCLASS");
	m_ClassStyleList.AddString("CS_HREDRAW");
	m_ClassStyleList.AddString("CS_NOCLOSE");
	m_ClassStyleList.AddString("CS_OWNDC");
	m_ClassStyleList.AddString("CS_PARENTDC");
	m_ClassStyleList.AddString("CS_SAVEBITS");
	m_ClassStyleList.AddString("CS_VREDRAW");

	m_ClassStyleList.SetItemData(0, CS_BYTEALIGNCLIENT);
	m_ClassStyleList.SetItemData(1, CS_BYTEALIGNWINDOW);
	m_ClassStyleList.SetItemData(2, CS_CLASSDC);
	m_ClassStyleList.SetItemData(3, CS_DBLCLKS);
	m_ClassStyleList.SetItemData(4, CS_GLOBALCLASS);
	m_ClassStyleList.SetItemData(5, CS_HREDRAW);
	m_ClassStyleList.SetItemData(6, CS_NOCLOSE);
	m_ClassStyleList.SetItemData(7, CS_OWNDC);
	m_ClassStyleList.SetItemData(8, CS_PARENTDC);
	m_ClassStyleList.SetItemData(9, CS_SAVEBITS);
	m_ClassStyleList.SetItemData(10, CS_VREDRAW);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPage2::ClearClassStyles()
{
	for(int i=0; i< m_ClassStyleList.GetCount(); ++i)
	{
		m_ClassStyleList.SetCheck(i,0);
	}
}

void CPage2::SetClassStyle(const char* lpszName)
{
	int idx = m_ClassStyleList.FindString(0,lpszName);
	if (idx > 0)
		m_ClassStyleList.SetCheck(idx, 1);
}

void CPage2::OnLbnCheckchangeListClassStyle()
{
	long style = 0;
	for(int i=0;i<m_ClassStyleList.GetCount();++i)
	{
		if(m_ClassStyleList.GetCheck(i))
			style |= m_ClassStyleList.GetItemData(i);
	}

	SetDlgItemText(IDC_EDITCLASSVALUE, Display((int)style));
	::SetClassLong(g_hWnd, GCL_STYLE, style);
}
